package com.spacecolony.service;

import android.content.Context;
import android.graphics.Color;

import com.spacecolony.dao.GameDAOStub;
import com.spacecolony.dao.IGameDAO;
import com.spacecolony.dao.OfflineGameDAO;
import com.spacecolony.model.Enemy;
import com.spacecolony.model.Player;
import com.spacecolony.model.UserAccount;
import com.spacecolony.model.World;
import com.spacecolony.model.WorldObject;

public class GameServiceStub implements IGameService {

	IGameDAO offlineGameDAO;
	UserAccount user;
	Enemy enemy;
	World world;
	
	/*
	 * Fetches account, sets enemy, and sets world
	 */
	public GameServiceStub(Context ctx) {
		offlineGameDAO = new OfflineGameDAO(ctx);
		try {
			startGame();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	/*
	 * {@inheritDoc}
	 */
	public UserAccount getUser() {
		//Gets user
		return user;
	}

	/**
	 * Sets the user
	 * @param user - the user to set
	 */
	public void setUser(UserAccount user) {
		this.user = user;
	}	
	
	@Override
	/*
	 * {@inheritDoc}
	 */
	public void startGame() throws Exception {
		fetchAccount();
		setEnemy();
		setWorld();	
	}

	/*
	 * {@inheritDoc}
	 */
	public Enemy getEnemy() {
		//gets enemy
		return enemy;
	}

	/**
	 * Sets enemy with attributes
	 */
	public void setEnemy() {
		enemy = new Enemy();
		enemy.setHp(10);
		enemy.setProjectileDamage(3);
	}

	/*
	 * {@inheritDoc}
	 */
	public World getWorld() {
		//Gets world
		return world;
	}

	/**
	 * Sets world with attributes
	 */
	public void setWorld() {
		world = new World();
		world.setRadius(5);
	}

	@Override
	/*
	 * {@inheritDoc}
	 */
	public void fetchAccount() {
		// Fetches account from DAO layer
		try {
			user = offlineGameDAO.loadAccount(0);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(user == null){
			user = new UserAccount();
			user.setUsername("New User");
			Player player = new Player();
			player.setHp(10);
			player.setProjectileDamage(3);
			player.setThrusterCapacity(10);
			user.setPlayer(player);
			try {
				user = offlineGameDAO.saveAccount(user);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	@Override
	/*
	 * {@inheritDoc}
	 */
	public void move() throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	/*
	 * {@inheritDoc}
	 */
	public void shoot() throws Exception {
		// TODO Auto-generated method stub

	}

}
